package com.tanhua.sso.server.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.tanhua.result.Result;
import com.tanhua.sso.pojo.UserInfo;
import com.tanhua.sso.server.service.MessagesService;
import com.tanhua.sso.utils.CommentType;
import com.tanhua.sso.vo.UserInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("messages")
public class MessagesController {

    @Autowired
    private MessagesService messagesService;

    /*返回环信用户信息*/
    @GetMapping("/userinfo")
    public ResponseEntity userinfo(String huanxinId){
        UserInfoVo userInfoVo=messagesService.findUserHuanXin(huanxinId);
     return ResponseEntity.ok(userInfoVo);
    }

    /**
     * 添加好友
     */
    @PostMapping("/contacts")
    public ResponseEntity contacts(@RequestBody Map map) {
        Long friendId = Long.valueOf(map.get("userId").toString());
        messagesService.contacts(friendId);
        return ResponseEntity.ok(null);
    }
    /*联系人列表*/
    @GetMapping("contacts")
    public ResponseEntity getContacts(@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "10") Integer pagesize,String keyword){
        Result result=messagesService.getContacts(page,pagesize,keyword);
        return ResponseEntity.ok(result);
    }

    /*点赞列表*/
    @GetMapping("likes")
    public ResponseEntity likes(@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "10") Integer pagesize){
        int type = CommentType.LIKE.getType();
        Result result=messagesService.likes(page,pagesize,type);
        return ResponseEntity.ok(result);
    }

    /*喜欢列表*/
    @GetMapping("loves")
    public ResponseEntity loves(@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "10") Integer pagesize){
        int type = CommentType.LOVE.getType();
        Result result=messagesService.likes(page,pagesize,type);
        return ResponseEntity.ok(result);
    }

    /*评论列表*/
    @GetMapping("comments")
    public ResponseEntity comments(@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "10") Integer pagesize){
        int type = CommentType.COMMENT.getType();
        Result result=messagesService.likes(page,pagesize,type);
        return ResponseEntity.ok(result);
    }

    /*公告列表*/
    @GetMapping("announcements")
    public ResponseEntity announcements(@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "10") Integer pagesize){
        Result result=messagesService.getAnnouncements(page,pagesize);
        return ResponseEntity.ok(result);
    }

}
